package com.wx.chapter10.final_.innerclass;

/**
 * ClassName:AnonymousInnerClass
 * Package :com.wx.chapter10.innerclass
 * Description :
 *
 * @Author : coder_mu
 * @Create : 2023/6/11 - 12:52
 */
public class AnonymousInnerClass {
    public static void main(String[] args) {
        Outer04 outer04 = new Outer04();
        outer04.method();
    }
}

class Outer04 {//外部类
    private int n1 = 10;//属性

    public void method() {//方法
        IA tiger = new IA() {//匿名内部类
            @Override
            public void cry() {
                System.out.println("老虎叫唤...");
            }
        };
        System.out.println("tiger 的运行类型=" + tiger.getClass());
        tiger.cry();
        tiger.cry();

        Father father = new Father("jack") {
            @Override
            public void test() {
                System.out.println("匿名内部类重写了 test 方法");
            }
        };

        System.out.println(("father 对象的运行类型=" + father.getClass()));
        father.test();
        Animal animal = new Animal() {
            @Override
            void eat() {
                System.out.println("小狗吃骨头...");
            }
        };
        System.out.println(("animal 对象的运行类型=" + animal.getClass()));

        animal.eat();
    }
}

interface IA {
    public void cry();
}

class Father {
    public Father() {
        System.out.println("Father的无参构造器");
    }

    public Father(String name) {
        System.out.println("接收到 name=" + name);
    }

    public void test() {
    }
}

abstract class Animal {
    abstract void eat();
}